﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public class WaitLoadPrefab : CustomYieldInstruction
    {
        private PrefabCache prefabcache;
        public GameObject LoadedObject { get; private set; }
        public string Error { get; private set; }

        public WaitLoadPrefab(PrefabCache cache)
        {
            this.prefabcache = cache;
        }

        public override bool keepWaiting
        {
            get
            {
                if (!string.IsNullOrEmpty(this.prefabcache.Error))
                {
                    this.Error = this.prefabcache.Error;
                    return false;
                }

                if (this.prefabcache.IsNotNull())
                {
                    this.LoadedObject = this.prefabcache.GetObject();
                    return false;
                }
                return true;
            }
        }



    }

}
